def pr (x):
    for i in range (2,int (x**0.5)+1):
        if x % i == 0:
            return False
            break
    return True




prime = []
for x in range (2,1000):
    if pr (x):
        prime.append (x)
#print (prime)

x= int (input())
if pr(x):
    print (x)
else:
    li = []
    x = str (x)
    li.append(int(x[0]))
    li.append(int(x[0:2]))
    li.append(int(x[0:3]))
    li.append(int(x[1:4]))
    li.append(int(x[2:4]))
    li.append(int(x[3:4]))
    li.append(int(x[1]))
    li.append(int(x[2]))
    li.append(int(x[3]))
    li.append(int(x[1:3]))
    li.append(int(x[2:4]))

    maxprime = 0
    print (li)
    for y in li:
        if pr (y):
            maxprime = max(maxprime, y)
    print (maxprime)
